<template>
  <div>
    <!-- 搜索区域 -->
    <el-card>
      <el-row>
        <el-col :span="8">
          商品名称：
          <el-input
            placeholder="商品名称"
            v-model="searchModel.goodsName"
            style="width: 300px; margin: 10px"
            clearable
          ></el-input>
        </el-col>
        <el-col :span="8">
          仓库名称：
          <el-select
            v-model="searchModel.warehouseName"
            filterable
            placeholder="请选择"
            style="width: 300px; margin: 10px"
            clearable
          >
            <el-option
              v-for="item in allwareHouseName"
              :key="item.id"
              :label="item.warehouseName"
              :value="item.warehouseName"
            >
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="8">
          分类：
          <el-select
            v-model="searchModel.goodsTypeId"
            filterable
            clearable
            placeholder="请选择"
            style="width: 300px; margin: 10px"
          >
            <el-option
              clearable
              v-for="item in goodTypeList"
              :key="item.id"
              :label="item.type"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="getProductList()"
            >查询</el-button
          >

          <el-button type="primary" @click="ProductEditUi(null)"
            >添加商品</el-button
          >
        </el-col>
        <el-col :span="12" align="right">
          <el-button type="primary" @click="exprotProduct"
            >导出设备档期</el-button
          >
        </el-col>
      </el-row>
    </el-card>

    <!-- 商品区域 -->
    <el-card>
      <el-table
        :data="productList"
        style="width: 100%"
        v-loading="loading"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column width="60">
          <template slot-scope="scope">
            <el-image
              v-if="scope.row.photoName != null"
              style="width: 50px; height: 50px"
              :src="scope.row.photoName"
              :preview-src-list="[scope.row.photoName]"
            >
              <div slot="error" class="image-slot">
                <el-image
                  style="width: 50px; height: 50px"
                  :src="qzImg"
                  :preview-src-list="[qzImg]"
                >
                  <div slot="error" class="image-slot">
                    <i class="el-icon-picture-outline"></i>
                  </div>
                </el-image>
              </div>
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="goodsName" label="商品" width="180">
        </el-table-column>

        <el-table-column prop="goodsType" label="分类" width="180">
        </el-table-column>

        <el-table-column label="库存" width="240">
          <template slot-scope="scope">
            <!-- 显示仓库名称,在仓库名称后面显示库存数量 -->
            <!-- {{ get }} -->
            <span
              v-for="warehouse in getAllProductDtoWarehouseName(
                scope.row.inventoryDto
              )"
              :key="warehouse.id"
            >
              <el-button
                size="mini"
                style="margin: 2px"
                @click="
                  selectinventorys({
                    warehouseId: warehouse.warehouseId,
                    productId: warehouse.productId,
                  })
                "
                >{{ warehouse.warehouseName }}: {{ warehouse.num }}台</el-button
              ></span
            >
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间"> </el-table-column>
        <el-table-column fixed="right" label="操作" width="360">
          <template slot-scope="scope">
            <el-button-group>
              <el-button
                type="primary"
                @click="ProductSelectAll(scope.row.id)"
                size="mini"
                >详 情</el-button
              >
              <el-button @click="addInventoryUi(scope.row)" size="mini"
                >库 存</el-button
              >
              <el-button @click="ProductEditUi(scope.row.id)" size="mini"
                >编 辑</el-button
              >
              <el-button
                @click="deleteProduct(scope.row.id)"
                size="mini"
                type="danger"
                >删 除</el-button
              >
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 分页组件 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchModel.pageNo"
      :page-sizes="[10, 20, 40, 100]"
      :page-size="searchModel.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>

    <!-- 新增分类 -->
    <el-dialog
      title="新增分类"
      :visible.sync="dialogFormVisibleGoodsType"
      width="360px"
      @close="cleaForm"
    >
      <el-form :model="goodTypeForm" ref="goodTypeFormRef">
        <el-form-item label="分类" size="mini">
          <el-input v-model="goodTypeForm.type" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisibleGoodsType = false" size="mini"
          >取 消</el-button
        >
        <el-button type="primary" @click="savegoodTypeForm" size="mini"
          >确 定</el-button
        >
      </div>
    </el-dialog>

    <el-drawer
      :title="title"
      :before-close="handleClose"
      @close="cleaForm"
      :visible.sync="dialogVisible"
      ref="productFormRef"
      size="40%"
    >
      <el-card>
        <el-form
          ref="productFormRef"
          :model="productForm"
          label-width="80px"
          :rules="rules"
        >
          <el-form-item label="商品名称" prop="goodsName">
            <el-input
              v-model="productForm.goodsName"
              placeholder="商品名称"
            ></el-input>
          </el-form-item>

          <el-form-item label="商品分类" prop="goodsTypeId">
            <el-row>
              <el-col :span="10">
                <el-select
                  v-model="productForm.goodsTypeId"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in goodTypeList"
                    :key="item.id"
                    :label="item.type"
                    :value="item.id"
                  >
                    <span style="float: left">{{ item.type }}</span>
                    <el-button
                      type="text"
                      icon="el-icon-close"
                      circle
                      size="mini"
                      style="float: right; margin-top: 3px"
                      @click="deleteTypeById(item.id)"
                    ></el-button>
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="14">
                <el-button
                  style="margin-right: 10px"
                  type="primary"
                  @click="GoodTypeUi"
                  >新增</el-button
                >
              </el-col>
            </el-row>
          </el-form-item>

          <el-form-item label="备注" prop="remark">
            <el-input
              type="textarea"
              placeholder="请输入内容"
              v-model="productForm.remark"
              maxlength="255"
              show-word-limit
            >
            </el-input>
          </el-form-item>

          <el-form-item label="商品图片">
            <!-- http://154.8.182.144:9999/sys/common/upload -->
            <!-- http://www.quzhi.org.cn:9999/sys/common/upload -->
            <el-upload
              action="http://154.8.182.144:9999/sys/common/upload"
              list-type="picture-card"
              :on-preview="handlePictureCardPreview"
              :on-success="handleAvatarSuccess"
              :on-remove="handleRemove"
              :before-upload="beforeAvatarUpload"
              :limit="1"
              :file-list="fileList"
              ref="uploadRef"
            >
              <i class="el-icon-plus"></i>
            </el-upload>
            <el-dialog :visible.sync="dialogVisiblePhoto">
              <img width="100%" :src="filename" alt="" />
            </el-dialog>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="saveProduct">确 定</el-button>
            <el-button @click="dialogVisible = false">取 消</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </el-drawer>

    <!-- 序列号详情列表 -->
    <el-dialog title="序列号详情" :visible.sync="dialogTableVisibleInventory">
      <el-table
        :data="inventorys"
        v-loading="inventoryLoading"
        max-height="250"
      >
        <el-table-column type="index" width="50" label="序号">
        </el-table-column>
        <el-table-column
          property="serialNumber"
          label="序列号"
          width="360"
        ></el-table-column>
        <el-table-column
          property="warehouseName"
          label="仓库"
          width="200"
        ></el-table-column>

        <el-table-column
          property="createTime"
          label="创建时间"
        ></el-table-column>
      </el-table>
    </el-dialog>

    <!-- 添加库存对话框 -->
    <el-dialog
      :title="addInventoryTitle"
      :visible.sync="dialogTableVisibleAddInventory"
      width="20%"
      :before-close="handleClose"
      @close="clearInventoryForm"
    >
      <el-dialog
        width="40%"
        title="添加序列号"
        :visible.sync="innerVisible"
        append-to-body
        :before-close="handleClose"
        @close="clearAddInventorys"
      >
        <el-row>
          <span class="demonstration"
            >注意：录入序列号，换行区分序列号</span
          ></el-row
        >
        <el-row style="margin-top: 20px">
          <el-col :span="10" style="margin-right: 60px">
            <el-input
              type="textarea"
              :rows="12"
              placeholder="请输入内容"
              v-model="inventoryText"
            >
            </el-input>
          </el-col>
          <el-col :span="10">
            <el-table :data="tempInventoryList" height="260" border>
              <el-table-column type="index" width="50" label="序号">
              </el-table-column>
              <el-table-column prop="serialNumber" label="序列号">
              </el-table-column>
            </el-table>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10" style="margin: 10px 80px">
            <el-button
              type="primary"
              size="mini"
              @click="analyzeText({ warehouseId: inventoryList.warehouseId })"
              >确 定</el-button
            ></el-col
          >
        </el-row>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="16">
            <span>已录入{{ tempInventoryList.length }}个</span></el-col
          ><el-col :span="8">
            <el-popconfirm
              title="确定要添加这些序列号吗"
              @onConfirm="saveTempInventoryToInventoryList"
            >
              <el-button size="mini" type="primary" slot="reference"
                >确 定</el-button
              >
            </el-popconfirm>

            <el-button
              size="mini"
              @click="innerVisible = false"
              style="margin-left: 10px"
              >取 消</el-button
            >
          </el-col>
        </el-row>
      </el-dialog>

      <el-form
        ref="inventoryListRef"
        :model="inventoryList"
        label-width="80px"
        :rules="addInventorysRules"
      >
        <el-form-item label="仓库名称" prop="warehouseId">
          <el-select
            v-model="inventoryList.warehouseId"
            filterable
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in allwareHouseName"
              :key="item.id"
              :label="item.warehouseName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="序列号">
          <el-row>
            <el-col :span="12"
              ><el-input
                placeholder="序列号数量"
                :disabled="true"
                width="10px"
                v-model="addInventoryList.length"
              >
              </el-input>
            </el-col>
            <el-col :span="12">
              <el-button
                type="primary"
                style="margin-left: 5px"
                @click="addInventorys()"
                size="mini"
                >新增</el-button
              >
            </el-col>
          </el-row>
        </el-form-item>

        <el-form-item label="备注">
          <el-input
            type="textarea"
            :rows="4"
            placeholder="请输入内容"
            v-model="inventoryList.remark"
          >
          </el-input>
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            @click="saveInventorys"
            size="mini"
            :loading="addLoading"
            >确 定</el-button
          >
          <el-button @click="dialogTableVisibleAddInventory = false" size="mini"
            >取 消</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import warehouseApi from "@/api/inventory/warehouse";
import productApi from "@/api/inventory/product";
import goodTypeApi from "@/api/inventory/goodsType";
import inventoryApi from "@/api/inventory/inventory";
import commonApi from "@/api/common";
import { getToken } from "@/utils/auth";

export default {
  data() {
    return {
      // 对话框是否可见
      dialogVisible: false,
      dialogFormVisibleGoodsType: false,
      dialogVisiblePhoto: false,
      multipleSelection: [],
      fileList: [{}],
      // 图片路径
      filename: "",

      loading: false,
      total: 0,
      searchModel: {
        pageNo: 1,
        pageSize: 10,
      },
      productList: [],

      productForm: {},

      goodTypeList: [],
      goodTypeForm: {},

      // 仓库名称
      allwareHouseName: [],

      // 序列号详情
      inventorys: [],
      dialogTableVisibleInventory: false,
      inventoryLoading: false,
      formLabelWidthInenvotry: "90px",

      // 内层对话框
      innerVisible: false,
      activeName: "first",

      title: "",
      rules: {
        goodsName: [
          { required: true, message: "请输入商品名称", trigger: "blur" },
          {
            min: 1,
            max: 50,
            message: "长度在 1 到 50 个字符",
            trigger: "blur",
          },
        ],

        goodsTypeId: [
          { required: true, message: "请选择分类", trigger: "change" },
        ],

        remark: [
          { message: "请输入商品名称", trigger: "blur" },
          {
            min: 0,
            max: 255,
            message: "长度在  到 255 个字符",
            trigger: "blur",
          },
        ],
      },
      addInventorysRules: {
        warehouseId: [
          { required: true, message: "请选择仓库", trigger: "change" },
        ],
      },
      qzImg: "http://154.8.182.144:9999/sys/common/download?name=quZhi.png",
      // qzImg: "http://www.quzhi.org.cn:9999/sys/common/download?name=quZhi.png",

      // 调整库存数量
      addInventoryTitle: "",
      dialogTableVisibleAddInventory: false,
      inventoryList: {},
      // 批量添加序列号文本域
      inventoryText: "",
      addInventoryList: [],
      tempInventoryList: [],
      inventoryNumber: 0,
      addLoading: false,
    };
  },
  methods: {
    handleSizeChange(pageSize) {
      this.searchModel.pageSize = pageSize;
      this.getProductList();
    },
    handleCurrentChange(pageNo) {
      this.searchModel.pageNo = pageNo;
      this.getProductList();
    },
    // 确认关闭对话框
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    // 上传图片成功
    handleAvatarSuccess(res, file) {
      this.productForm.photoName = res.data;
      this.filename = res.data;
    },
    // 清理表单数据
    cleaForm() {
      // 清理数据
      this.productForm = {};
      if (
        this.$refs.productFormRef != null ||
        this.$refs.productFormRef != undefined
      ) {
        this.$refs.productFormRef.clearValidate();
      }

      this.goodTypeForm = {};

      if (
        this.$refs.goodTypeFormRef != null &&
        this.$refs.goodTypeFormRef != undefined
      ) {
        this.$refs.goodTypeFormRef.clearValidate();
      }

      // 清除图片
      if (this.$refs.uploadRef != null && this.$refs.uploadRef != undefined) {
        this.$refs.uploadRef.clearFiles();
      }
    },
    clearInventoryForm() {
      this.inventoryList = {};
      this.addInventoryList = [];

      if (
        this.$refs.inventoryListRef != null &&
        this.$refs.inventoryListRef != undefined
      ) {
        this.$refs.inventoryListRef.clearValidate();
      }
      this.addLoading = false;
    },
    clearAddInventorys() {
      // 批量添加序列号文本域
      this.inventoryText = "";
      this.tempInventoryList = [];
    },

    // 显示订单处理UI
    ProductEditUi(productId) {
      if (productId == null || productId == undefined) {
        // 清空数据

        this.clearInventoryForm();

        this.fileList = [];
        this.title = "新增商品";
        this.dialogVisible = true;
      } else {
        this.title = "修改商品";
        // 查询商品
        productApi.getproductById(productId).then((response) => {
          this.productForm = response.data;
          this.dialogVisible = true;

          // 回显图片
          if (
            this.productForm.photoName != null &&
            this.productForm.photoName != undefined &&
            this.productForm.photoName !== ""
          ) {
            // 设置图片图片
            this.filename =
              this.productForm.photoName.split("name=")[
                this.productForm.photoName.split("name=").length - 1
              ];
            this.fileList = [
              { name: this.filename, url: this.productForm.photoName },
            ];
          } else {
            this.filename = "";
            this.fileList = [];
          }
        });
      }
    },

    getProductList() {
      this.loading = true;
      productApi.getProductList(this.searchModel).then((response) => {
        this.productList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
        this.getGoodsTypeList();
      });
    },

    // 新增商品UI
    GoodTypeUi() {
      this.dialogFormVisibleGoodsType = true;
      this.getGoodsTypeList();
    },

    // 保存分类
    savegoodTypeForm() {
      this.$refs.goodTypeFormRef.validate((valid) => {
        if (valid) {
          // 提交数据给后台
          // 设置图片名称

          goodTypeApi.saveType(this.goodTypeForm).then((response) => {
            if (response.code === 20000) {
              this.$message({
                showClose: true,
                message: response.message,
                type: "success",
              });
              // 关闭对话框
              this.dialogFormVisibleGoodsType = false;
              // 刷新表单
              this.getGoodsTypeList();
            } else {
              this.$message({
                showClose: true,
                message: response.message,
                type: "error",
              });
              this.getGoodsTypeList();
            }
          });
        } else {
          // 验证不通过
          this.$message({
            showClose: true,
            message: "表单验证不通过",
            type: "error",
          });
          return false;
        }
      });
    },
    // 上传
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isLt2M;
    },

    saveProduct() {
      this.$refs.productFormRef.validate((valid) => {
        if (valid) {
          // 提交数据给后台
          productApi.saveProductr(this.productForm).then((response) => {
            if (response.code === 20000) {
              this.$message({
                showClose: true,
                message: response.message,
                type: "success",
              });
              // 关闭对话框
              this.dialogVisible = false;
              // 刷新表单
              this.getProductList();
            } else {
              this.$message({
                showClose: true,
                message: response.message,
                type: "error",
              });
              this.getProductList();
            }
          });
        } else {
          // 验证不通过
          this.$message({
            showClose: true,
            message: "表单验证不通过",
            type: "error",
          });
          return false;
        }
      });
    },

    getGoodsTypeList() {
      goodTypeApi.getTypeList().then((response) => {
        this.goodTypeList = response.data;
      });
    },

    // 删除分类
    deleteTypeById(id) {
      goodTypeApi.deleteTypeById(id).then((response) => {
        this.$message("删除成功");
        this.getGoodsTypeList();
        // 情况当前选择的内容
        this.productForm.goodsType = "";
      });
    },

    // 商品图片
    handleRemove(file, fileList) {
      if (file.response != null && file.response != undefined) {
        this.deleteImg(file.response.data);
      } else {
        if (file.name != null && file.name != undefined) {
          if (
            file.name.split("=")[1] != null &&
            file.name.split("=")[1] != undefined
          ) {
            this.deleteImg(file.name.split("=")[1]);
          }
        }
        this.deleteImg(file.name);
      }
    },

    deleteImg(filename) {
      commonApi.deleteImg(filename);
    },

    handlePictureCardPreview(file) {
      this.filename = file.url;
      this.dialogVisiblePhoto = true;
    },
    // 复选框内容
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    // 删除商品
    deleteProduct(id) {
      this.$confirm(`您确删除该商品吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          productApi.deleteProductById(id, getToken()).then((response) => {
            this.$message({
              type: "success",
              message: response.message,
            });
            this.getProductList();
          });
        })

        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 跳转详情页
    ProductSelectAll(id) {
      this.$router.push({ path: "/inventorys/index", query: { id: id } });
    },

    // 获取所有仓库名称
    getAllwareHouseName() {
      warehouseApi.selseAllName().then((response) => {
        this.allwareHouseName = response.data;
      });
    },

    // 获取元素中所有的仓库名称
    getAllProductDtoWarehouseName(prodcutDto) {
      // 使用一个对象来存储仓库名称及其对应的个数
      const warehouseCount = {};

      // 遍历列表进行统计
      prodcutDto.forEach((item) => {
        const warehouseName = item.warehouseName;

        // 如果该仓库名称已经在 warehouseCount 对象中存在，则增加计数
        if (warehouseCount[warehouseName]) {
          warehouseCount[warehouseName].num++;
        } else {
          // 否则，初始化计数为 1
          warehouseCount[warehouseName] = {
            num: 1,
            productId: item.productId,
            warehouseId: item.warehouseId,
            warehouseName: item.warehouseName,
          };
        }
      });

      return warehouseCount;
      // 输出结果
    },

    // 显示序列号详情列表
    selectinventorys(model) {
      this.inventoryLoading = true;
      this.dialogTableVisibleInventory = true;
      inventoryApi.getWarehouseInventory(model).then((response) => {
        this.inventorys = response.data;
        this.inventoryLoading = false;
      });
    },

    // 添加库存
    addInventoryUi(product) {
      this.inventoryList = {
        productId: product.id,
      };
      this.addInventoryTitle = "调整库存数量-" + product.goodsName;
      this.dialogTableVisibleAddInventory = true;
    },

    addInventorys() {
      // 表单验证
      this.$refs.inventoryListRef.validate((valid) => {
        if (valid) {
          this.innerVisible = true;
        } else {
          // 验证不通过
          this.$message({
            showClose: true,
            message: "表单验证不通过",
            type: "error",
          });
          return false;
        }
      });
    },
    // 添加序列号

    // 解析文本域中的序列号
    analyzeText(inventory) {
      let uniqueStrings = [];
      let seenStrings = {};

      var inputList = this.inventoryText.split("\n");
      if (
        inputList == null ||
        inputList == undefined ||
        inputList.length == 0
      ) {
        this.$message({
          message: "请输入序列号",
          type: "warning",
        });
      } else {
        for (let str of inputList) {
          // Step 1: 判断空白字符串
          if (str.trim() === "") {
          } // Step 2: 判断重复字符串
          else if (seenStrings[str]) {
            this.$message({
              message: `重复字符串：${str}`,
              type: "warning",
            });
          } else {
            seenStrings[str] = true;
            // Step 3: 添加不重复的字符串到另一个列表中
            uniqueStrings.push(str);
          }
        }
      }

      if (uniqueStrings.length > 0) {
        uniqueStrings.forEach((item) => {
          this.tempInventoryList.push({
            productId: this.inventoryList.productId,
            warehouseId: inventory.warehouseId,
            serialNumber: item,
          });
        });
      }
      // 清空文本域中的字符串
      this.inventoryText = "";
    },

    // 保存临时序列号存储对象到数据源列表中
    saveTempInventoryToInventoryList() {
      if (this.tempInventoryList.length > 0) {
        for (const temp of this.tempInventoryList) {
          var flag = true;
          for (const inventory of this.addInventoryList) {
            if (temp == inventory) {
              flag = false;
              break;
            }
          }
          if (flag) {
            this.addInventoryList.push(temp);
          } else {
            this.$message("重复序列号未添加");
          }
        }
      }
      this.innerVisible = false;
    },

    // 批量保存序列号商品
    saveInventorys() {
      // 判断序列号列表是否为空
      this.$confirm(
        `要添加的序列号数量是${this.addInventoryList.length}个, 您确认要添加吗？`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          if (this.addInventoryList.length > 0) {
            this.addLoading = true;

            inventoryApi
              .addInventorys(this.addInventoryList, this.inventoryList.remark)
              .then((response) => {
                if (response.code === 20000) {
                  this.$message({
                    showClose: true,
                    message: response.message,
                    type: "success",
                  });
                  this.addLoading = false;
                  this.dialogTableVisibleAddInventory = false;
                  // 刷新表单
                  this.getProductList();
                } else {
                  this.$message({
                    showClose: true,
                    message: response.message,
                    type: "error",
                  });
                  this.addLoading = false;
                  this.getProductList();
                }
              });
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消添加",
          });
        });
    },

    // 导出设备档期
    exprotProduct() {
      // 判断序列号列表是否为空
      this.$confirm(`确定要导出当前的设备档期表吗，记得先查寄回。`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        if (
          this.searchModel.warehouseName == null ||
          this.searchModel.warehouseName == undefined ||
          this.searchModel.warehouseName === ""
        ) {
          this.$message({
            type: "warning",
            message: "请选择导出仓库",
          });
        } else {
          var warehouseId = "";
          for (const warehouse of this.allwareHouseName) {
            if (warehouse.warehouseName === this.searchModel.warehouseName) {
              warehouseId = warehouse.id;
              break;
            }
          }
          window.open(
            productApi.DownlaodProductList + `?warehouseId=${warehouseId}`
          );
        }
      });
    },
  },

  created() {
    this.getProductList();
    this.getAllwareHouseName();
  },
};
</script>

<style scoped></style>
